﻿using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using NPOI.SS.Formula.Functions;
using NuGet.Common;
using System.Drawing.Printing;
using WMSUIMVC.DTO.Foundation;
using XuanKeZz.Application.HTTP;
using static System.Runtime.InteropServices.JavaScript.JSType;

namespace WMSUIMVC.Controllers
{
    /// <summary>
    /// 基础模块
    /// </summary>
    public class FoundationController : Controller
    {

        private readonly IConfiguration _configuration;

        public FoundationController(IConfiguration configuration)
        {
            _configuration = configuration;
        }


        public IActionResult Index()
        {
            return View();
        }

     #region 仓库

        /// <summary>
        /// 仓库列表方法
        /// </summary>
        /// <param name="token"></param>
        /// <param name="Oid"></param>
        /// <param name="Uid"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public async Task<IActionResult> GetDatalist(WareDTO list)
        {
            
            HttpClientWrapper client = new HttpClientWrapper(list.Token);
            string url = _configuration["Url"]+"ckd/api/ReadWarehouse/GetWarehouseList?pageIndex="+list.pageIndex+"&PageSize="+list.PageSize+"&wareCode="+list.wareCode+"&wareName="+list.wareName+"&type="+list.type+ "&DpmId="+list.DpmId; 
            string Getwarehouse = await client.GetAsync(url);
            return Json(Getwarehouse);
        }

        /// <summary>
        ///仓库删除(单删)
        /// </summary>
        /// <param name="token"></param>
        /// <param name="WarehouseId"></param>
        /// <returns></returns>
        public async Task<IActionResult> DeleteWarehouse(DelWareDTO data)
        {
            
            HttpClientWrapper client = new HttpClientWrapper(data.Token);
            string url = _configuration["Url"] + "ckx/api/Warehouse/BatchDelWarehous";
      
            var list = JsonConvert.SerializeObject(data);
            string Getwarehouse = await client.PutAsync(url, list);
            return Json(Getwarehouse);
        }

        /// <summary>
        /// 批删
        /// </summary>
        /// <param name="token"></param>
        /// <param name="WarehouseId"></param>
        /// <returns></returns>
        public async Task<IActionResult> BatchDelWare(DelWareDTO data)
        {
           
            HttpClientWrapper client = new HttpClientWrapper(data.Token);
            string url = _configuration["Url"] + "ckx/api/Warehouse/BatchDelWarehous";
            var list = JsonConvert.SerializeObject(data);
            string Getwarehouse = await client.PutAsync(url, list);
            return Json(Getwarehouse);
        }

      

        /// <summary>
        /// 反填仓库信息
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpGet]
        public  async Task<IActionResult> GetWareInfo(FillWareDTO data)
        {
         
            HttpClientWrapper client = new HttpClientWrapper(data.Token);
            string url = _configuration["Url"] + "ckd/api/ReadWarehouse/GetWarehouseById?Id=" + data.Id;
            string Getwarehouse = await client.GetAsync(url);
            return Json(Getwarehouse);
        }

        /// <summary>
        /// 修改仓库信息
        /// </summary>
        /// <param name="token"></param>
        /// <param name="WarehouseId"></param>
        /// <returns></returns>
        public async Task<IActionResult> UpdateWarehouseInfo(AddWare file)
        {
           
            HttpClientWrapper client = new HttpClientWrapper(file.Token);
            string url = _configuration["Url"] + "ckx/api/Warehouse/UpdateWarehouse";
            var list = JsonConvert.SerializeObject(file);
            string Getwarehouse = await client.PutAsync(url,list);
            return Json(Getwarehouse);
        }


        /// <summary>
        /// 添加仓库信息
        /// </summary>
        /// <param name="token"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> AddWarehouseInfo(AddWare field)
        {
            
            HttpClientWrapper client = new HttpClientWrapper(field.Token);
            string url = _configuration["Url"] + "ckx/api/Warehouse/WarehouseAdd";
            var list = JsonConvert .SerializeObject(field);
            string Getwarehouse = await client.PostAsync(url, list);
            return Json(Getwarehouse);
        }





        /// <summary>
        /// 仓库管理
        /// </summary>
        /// <returns></returns>
        public  IActionResult GetWarehouse()
        {
            return View();
        }

        /// <summary>
        /// 添加仓库信息
        /// </summary>
        /// <returns></returns>
        public IActionResult AddWarehouse()
        {
            return View();
        }

        /// <summary>
        /// 更新仓库信息
        /// </summary>
        /// <returns></returns>
        public IActionResult UptWarehouse()
        {
            return View();
        }

        #endregion



     #region 库位
        /// <summary>
        /// 库位管理
        /// </summary>
        /// <returns></returns>
        public IActionResult GetStorehouseList()
        {
                return View();
        }

        /// <summary>
        /// 库位信息列表
        /// </summary>
        /// <param name="token"></param>
        /// <param name="Oid"></param>
        /// <param name="Uid"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public async Task<IActionResult> GetStorehouse(StorehouseListDTO list)
        {
            HttpClientWrapper client = new HttpClientWrapper(list.Token);
            string url = _configuration["Url"] + "ckd/api/ReadStorehouse/GetStorehouseList?pageIndex=" + list.pageIndex + "&PageSize=" + list.PageSize+"&StoreCode="+list.StoreCode+"&StoreName="+list.StoreName+"&wid="+list.wid;
            string Getwarehouse = await client.GetAsync(url);
            return Json(Getwarehouse);
        }



        /// <summary>
        /// 库位下的仓库信息
        /// </summary>
        /// <param name="token"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> GetWare(string token)
        {
            
            HttpClientWrapper client = new HttpClientWrapper(token);
            string url = _configuration["Url"] + "ckd/api/ReadStorehouse/GetWarelist";
            string Getwarehouse = await client.GetAsync(url);
            return Json(Getwarehouse);
        }

        /// <summary>
        /// 添加库位信息
        /// </summary>
        /// <returns></returns>
        public IActionResult AddStorehouse()
        {
            return View();
        }

     
        /// <summary>
        /// 添加库位信息
        /// </summary>
        /// <returns></returns>
        public async Task<IActionResult> AddStoreInfo(AddStoreDTO field)
        {
           
            HttpClientWrapper client = new HttpClientWrapper(field.Token);
            string url = _configuration["Url"] + "ckx/api/Storehouse/AddStorehouse";
            var list = JsonConvert.SerializeObject(field);
            string Getwarehouse = await client.PostAsync(url,list);
            return Json(Getwarehouse);
        }

  


    

        /// <summary>
        /// 删除库位信息
        /// </summary>
        /// <returns></returns>
        public async Task<IActionResult> DelStore(DelStoreDTO del)
        {
           
            HttpClientWrapper client = new HttpClientWrapper(del.Token);
            string url = _configuration["Url"] + "ckx/api/Storehouse/Delstorehouse";
            var list = JsonConvert.SerializeObject(del);
            string Getwarehouse = await client.PutAsync(url, list);
            return Json(Getwarehouse);
        }
        /// <summary>
        /// 反填
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public async Task<IActionResult> GetStoreInfo(FillStoreDTO data)
        {
           
            HttpClientWrapper client = new HttpClientWrapper(data.Token);
            string url = _configuration["Url"] + "ckd/api/ReadStorehouse/GetStorehouseInfo?Id=" +data.Id;
            string Getwarehouse = await client.GetAsync(url);
            return Json(Getwarehouse);
        }

        /// <summary>
        /// 修改库位信息
        /// </summary>
        /// <param name="filed"></param>
        /// <returns></returns>
        public async Task<IActionResult> UptStore(AddStoreDTO filed)
        {
           
            HttpClientWrapper client = new HttpClientWrapper(filed.Token);
            string url = _configuration["Url"] + "ckx/api/Storehouse/UptStorehouse";
            var list = JsonConvert.SerializeObject(filed);
            string Getwarehouse = await client.PutAsync(url, list);
            return Json(Getwarehouse);
        }


        /// <summary>
        /// 更新库位信息
        /// </summary>
        public IActionResult UptStorehouse()
        {
            return View();
        }



        #endregion



     #region 设备

        /// <summary>
        /// 设备管理
        /// </summary>
        /// <returns></returns>
        public IActionResult EquipmentList()
        {
            return View();
        }



        /// <summary>
        /// 设备列表
        /// </summary>
        /// <param name="token"></param>
        /// <param name="Oid"></param>
        /// <param name="Uid"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public async Task<IActionResult> GetEquipment(EquipementListDTO list)
        {
           
            HttpClientWrapper client = new HttpClientWrapper(list.Token);
            string url = _configuration["Url"] + "sbd/api/Equipment/GetEquipmentList?PageIndex=" + list.PageIndex + "&PageSize=" + list.PageSize+ "&Code=" + list.Code+ "&Name=" + list.Name;
            string Getwarehouse = await client.GetAsync(url);
            return Json(Getwarehouse);
        
        }
   

        /// <summary>
        /// 添加设备信息
        /// </summary>
        /// <param name="field"></param>
        /// <returns></returns>
        public async Task<IActionResult> AddEquipment(AddEquipment field)
        {
           
            HttpClientWrapper client = new HttpClientWrapper(field.Token);
            string url = _configuration["Url"] + "sbx/api/Equipment/AddEquipment";
            string Getwarehouse = await client.PostAsync(url, JsonConvert.SerializeObject(field));
            return Json(Getwarehouse);

        }

        /// <summary>
        /// 反填设备信息
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public async Task<IActionResult> GetEquipmentInfo(FillEquipment fill)
        {
            
            HttpClientWrapper client = new HttpClientWrapper(fill.Token);
            string url = _configuration["Url"] + "sbd/api/Equipment/FileEquipmentInfo?EquipmentId="+fill.EquipmentId;
            string Getwarehouse = await client.GetAsync(url);
            return Json(Getwarehouse);
        }

        /// <summary>
        /// 修改设备信息
        /// </summary>
        /// <param name="field"></param>
        /// <returns></returns>
        public async Task<IActionResult> UptEquipment(AddEquipment field)
        {
         
            HttpClientWrapper client = new HttpClientWrapper(field.Token);
            string url = _configuration["Url"] + "sbx/api/Equipment/UptEquipment";
            string Getwarehouse = await client.PutAsync(url, JsonConvert.SerializeObject(field));
            return Json(Getwarehouse);

        }


        /// <summary>
        /// 删除设备信息
        /// </summary>
        /// <param name="del"></param>
        /// <returns></returns>
        public async Task<IActionResult> DelEquipment(DelEquipment del)
        {
         
            HttpClientWrapper client = new HttpClientWrapper(del.Token);
            string url = _configuration["Url"] + "sbx/api/Equipment/DelEquipment";
            string Getwarehouse = await client.PutAsync(url, JsonConvert.SerializeObject(del));
            return Json(Getwarehouse);
        }

        #endregion

    }
}
